/*************************************************************************
    > File Name: exporter-dummy.c
    > Author: baiy
    > Mail: baiyang0223@163.com 
    > Created Time: 2020-10-26-18:57:51
    > Func: 
 ************************************************************************/
#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
#include <linux/init.h>
#include <linux/module.h>
#include <linux/kernel.h>
#include <linux/fs.h>
#include <linux/slab.h>
#include <linux/uaccess.h>
#include <linux/version.h>

#include <linux/dma-buf.h>

static struct sg_table *exporter_map_dma_buf(struct dma_buf_attachment *attachment,
					 enum dma_data_direction dir)
{
	return NULL;
}

static void exporter_unmap_dma_buf(struct dma_buf_attachment *attachment,
			       struct sg_table *table,
			       enum dma_data_direction dir)
{
}

static void exporter_release(struct dma_buf *dmabuf)
{
}

static void *exporter_kmap_atomic(struct dma_buf *dmabuf, unsigned long page_num)
{
	return NULL;
}

static void *exporter_kmap(struct dma_buf *dmabuf, unsigned long page_num)
{
	return NULL;
}

static void exporter_kunmap(struct dma_buf *dmabuf, unsigned long page_num, void * call_back)
{
	return;
}

static int exporter_mmap(struct dma_buf *dmabuf, struct vm_area_struct *vma)
{
	return -ENODEV;
}

static const struct dma_buf_ops exp_dmabuf_ops = {
	.map_dma_buf = exporter_map_dma_buf,
	.unmap_dma_buf = exporter_unmap_dma_buf,
	.release = exporter_release,
#if 0
	.map_atomic = exporter_kmap_atomic,
#endif
	.map = exporter_kmap,
	.unmap = exporter_kunmap,
	.mmap = exporter_mmap,
};

static int __init exporter_init(void)
{
	DEFINE_DMA_BUF_EXPORT_INFO(exp_info);
	struct dma_buf *dmabuf;

	pr_info("init [E]\n");
	exp_info.ops = &exp_dmabuf_ops;
	exp_info.size = PAGE_SIZE;
	exp_info.flags = O_CLOEXEC;
	exp_info.priv = "null";

	dmabuf = dma_buf_export(&exp_info);

	pr_info("init [X]\n");
	return 0;
}


static void __exit exporter_exit(void)
{
    pr_info("exit [E]\n");
    pr_info("exit [X]\n");
}
module_init(exporter_init);
module_exit(exporter_exit);
MODULE_LICENSE("GPL v2");
